package com.offcn.controller;

import com.github.pagehelper.PageInfo;
import com.offcn.pojo.Blog;
import com.offcn.service.BlogService;
import com.offcn.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController //等价于@Controller + @ResponseBody
@RequestMapping("blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    //列表展示
    @GetMapping("list")
    public PageInfo<Blog>list(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "3") int pageSize){
        return blogService.queryList(currentPage,pageSize);
    }

    //删除操作
    @GetMapping("delete")
    public Result delete(int id){
        blogService.delete(id);
        return new Result(true,"操作成功");
    }

    //博客详情
    @GetMapping("detail")
    public Blog detail(int id){
        return blogService.queryById(id);
    }
}
